package com.dlc.apk.ui.model

import android.view.View
import androidx.databinding.Observable
import androidx.databinding.Observable.OnPropertyChangedCallback
import androidx.databinding.ObservableBoolean
import androidx.databinding.ObservableField
import androidx.databinding.ObservableInt
import com.dlc.apk.utils.LogPlus
import java.util.*

class AppForm : BaseModel() {
    @JvmField
    val versionName = ObservableField<String>()

    @JvmField
    val welcome = ObservableField("Welcome")

    @JvmField
    val isDebug = ObservableBoolean(true)

    @JvmField
    val iconUrl = ObservableField<String>()
    val users: ArrayList<User> = ArrayList()

    @JvmField
    val visibility: ObservableInt = object : ObservableInt(isDebug) {
        override fun get(): Int {
            return if (isDebug.get()) {
                View.VISIBLE
            } else View.GONE
        }
    }
    val isShowLogoBar = ObservableBoolean(true)

    @JvmField
    val logoBarVisibility: ObservableInt = object : ObservableInt(isShowLogoBar) {
        override fun get(): Int {
            return if (isShowLogoBar.get()) {
                View.VISIBLE
            } else View.GONE
        }
    }

    init {
        isDebug.addOnPropertyChangedCallback(object : OnPropertyChangedCallback() {
            override fun onPropertyChanged(sender: Observable, propertyId: Int) {
                LogPlus.e("###isDebug发生变化, sender->$sender,propertyId->$propertyId")
                if (sender === isDebug) {
                    LogPlus.e("sender == isDebug")
                }
            }
        })
    }

    @JvmField
    val status = ObservableField("")
}